package com.example.mobile2021606137xzt0429homework;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class ParkRVAdapter extends RecyclerView.Adapter<ParkRVAdapter.ViewHolder> {
    private List<part> list;

    public ParkRVAdapter(List<part> list) {
        this.list = list;
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        ImageView ivp;
        TextView tvname, tvkongwei, tvprice, tvjuli, tvaddress, tvmes;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            ivp = itemView.findViewById(R.id.iv_item_p);
            tvname = itemView.findViewById(R.id.tv_item_name);
            tvkongwei = itemView.findViewById(R.id.tv_item_kongwei);
            tvprice = itemView.findViewById(R.id.tv_item_price);
            tvjuli = itemView.findViewById(R.id.tv_item_juli);
            tvaddress = itemView.findViewById(R.id.tv_item_address);
            tvmes = itemView.findViewById(R.id.tv_item_mes);
        }
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_rv_main_part, parent, false);
        return new ViewHolder(view);
    }
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder,int position){
        part part=list.get(position);
        holder.tvname.setText(part.getName());
        holder.tvkongwei.setText(part.getKongwei());
        holder.tvprice.setText(part.getPrice());
        holder.tvaddress.setText(part.getAddress());
        holder.tvjuli.setText(part.getJuli());
        holder.tvmes.setText(part.getMes());
        holder.ivp.setImageResource(part.getIvp());
    }
    @Override
    public int getItemCount(){
        return list.size();
    }
}
